//
// Created by gnehcnij on 2021/11/3.
//

#ifndef INSPECT_SQLITE3_COMMONUTILS_H
#define INSPECT_SQLITE3_COMMONUTILS_H

/*
** These are the allowed modes.
*/
#define MODE_Line     0  /* One column per line.  Blank line between records */
#define MODE_Column   1  /* One record per line in neat columns */
#define MODE_List     2  /* One record per line with a separator */
#define MODE_Semi     3  /* Same as MODE_List but append ";" to each line */
#define MODE_Html     4  /* Generate an XHTML table */
#define MODE_Insert   5  /* Generate SQL "insert" statements */
#define MODE_Quote    6  /* Quote values as for SQL */
#define MODE_Tcl      7  /* Generate ANSI-C or TCL quoted elements */
#define MODE_Csv      8  /* Quote strings, numbers are plain */
#define MODE_Explain  9  /* Like MODE_Column, but do not truncate data */
#define MODE_Ascii   10  /* Use ASCII unit and record separators (0x1F/0x1E) */
#define MODE_Pretty  11  /* Pretty-print schemas */
#define MODE_EQP     12  /* Converts EXPLAIN QUERY PLAN output into a graph */
#define MODE_Json    13  /* Output JSON */
#define MODE_Markdown 14 /* Markdown formatting */
#define MODE_Table   15  /* MySQL-style table formatting */
#define MODE_Box     16  /* Unicode box-drawing characters */

#define IsSpace(X)  isspace((unsigned char)(X))
#define IsDigit(X)  isdigit((unsigned char)(X))
#define ToLower(X)  (char)tolower((unsigned char)(X))

void out_of_memory();

/*
** Return the length of a string in characters.  Multibyte UTF8 characters
** count as a single character.
*/
int strlenChar(const char *z);

/*
** Print N dashes
*/
void print_dashes(FILE *out, int N);

/*
** Print a markdown or table-style row separator using ascii-art
*/
void print_row_separator(
        FILE *out,
        int *actualWidth,
        int nArg,
        const char *zSep
);

/*
** Output string zUtf to stream pOut as w characters.  If w is negative,
** then right-justify the text.  W is the width in UTF-8 characters, not
** in bytes.  This is different from the %*.*s specification in printf
** since with %*.*s the width is measured in bytes, not characters.
*/
void utf8_width_print(FILE *pOut, int w, const char *zUtf);

/*
** Compute a string length that is limited to what can be stored in
** lower 30 bits of a 32-bit signed integer.
*/
int strlen30(const char *z);

#endif //INSPECT_SQLITE3_COMMONUTILS_H
